package com.cuit.qx.utils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class AqiSortRankUtil {


    public static  String aqiSortRank(Map<String, BigDecimal> map,BigDecimal AqiMax){

        int flag=0;
        StringBuilder builder=new StringBuilder();
        if (map.get("so2").compareTo(AqiMax)==1){
            flag++;
           builder.append("SO2");
        }

        if (map.get("no2").compareTo(AqiMax)==0){
            if (flag!=0){
                builder.append(",NO2");
            }else {
                builder.append("NO2");
            }
            flag++;
        }

        if (map.get("o3").compareTo(AqiMax)==0){

            if (flag!=0){
                builder.append(",O3");
            }else{
                builder.append("O3");
            }
            flag++;
        }

        if (map.get("co").compareTo(AqiMax)==0){

            if (flag!=0){
                builder.append(",CO");
            }else {
                builder.append("CO");
            }
            flag++;
        }
        if (map.get("pm10").compareTo(AqiMax)==0){

            if (flag!=0){
                builder.append(",PM10");
            }else {
                builder.append("PM10");
            }
            flag++;
        }
        if (map.get("pm25").compareTo(AqiMax)==0){
            if (flag!=0){
                builder.append(",PM2.5");
            }   else {
                builder.append("PM2.5");
            }
            flag++;
        }

        return builder.toString();

    }


    public static void main(String[] args) {
        Map<String,BigDecimal> map =new HashMap <>(); //存AQI 和 污染物名字
        map.put("so2",new BigDecimal(20));
        map.put("no2",new BigDecimal(20));
        map.put("o3",new BigDecimal(20));
        map.put("co",new BigDecimal(40));
        map.put("pm10",new BigDecimal(30));
        map.put("pm25",new BigDecimal(20));
        String s = AqiSortRankUtil.aqiSortRank(map, new BigDecimal(20));
        System.out.println(s);
    }
}
